package org.xinjiang.tarim.travel.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.xinjiang.tarim.travel.mapper.RouteDayMapper;
import org.xinjiang.tarim.travel.model.RouteDay;
import org.xinjiang.tarim.travel.model.RouteDayPoi;
import org.xinjiang.tarim.travel.service.RouteDayPoiService;
import org.xinjiang.tarim.travel.service.RouteDayService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RouteDayServiceImpl implements RouteDayService {
    @Autowired
    RouteDayMapper routeDayMapper;
    @Autowired
    RouteDayPoiService routeDayPoiService;

    @Override
    public int insert(List<RouteDay> routeDays) {
        return routeDayMapper.insert(routeDays);
    }

    @Override
    public List selectByRouteId(Long routeId) {
        List<RouteDay> routeDays = routeDayMapper.selectByRouteId(routeId);
        List list = new ArrayList();
        for(RouteDay routeDay : routeDays){
            Map map = new HashMap();
            List<RouteDayPoi> routeDayPois = routeDayPoiService.selectByRouteDayId(routeDay.getId());
            map.put("routeDay", routeDay);
            map.put("routeDayPoi", routeDayPois);
            list.add(map);
        }
        return list;
    }

    @Override
    public int updateForRelease(List<RouteDay> list) {
        return routeDayMapper.updateForRelease(list);
    }
}
